package kislo.dima.task4;

public class Multiplicator {

	public static Matrix multiply(Matrix a, Matrix b)
			throws MultiplicationException {
		int mSizeA = a.getRowCount();
		int nSizeA = a.getColumnCount();
		int mSizeB = b.getRowCount();
		int nSizeB = b.getColumnCount();

		if (nSizeA != mSizeB)
			throw new MultiplicationException();

		Matrix c = new Matrix(mSizeA, nSizeB);

		// multiply
		int value = 0;
		for (int i = 0; i < mSizeA; i++) {
			for (int j = 0; j < nSizeB; j++) {
				value = 0;
				for (int k = 0; k < nSizeA; k++) {
					value += a.getElement(i, k) * b.getElement(k, j);
				}
				c.setElement(i, j, value);
			}
		}
		
		return c;
	}

}
